/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        
        vector<vector<int>> ve;  
        if(!root){
            return ve;
        }

        queue<TreeNode*> q;                // 利用队列特性插入元素
        q.push(root);

        while(q.size()){
        int  cursize=q.size();       //当前有几个结点  
        ve.push_back(vector<int>());                  
        for(int i=0;i<cursize;i++){
            auto n=q.front();        //取出结点
            q.pop();
            ve.back().push_back(n->val) ;     //最后一个链表插入
            if(n->left)
            q.push(n->left);
            if(n->right)
            q.push(n->right);

        }
        }
        return ve;

    }
};